package com.itheima.d4_algorithm;

import java.util.Arrays;

/**
 * 目标：掌握冒泡排序的编写。
 */
public class Test1 {
    //冒泡排序


    //从索引0开始到length-1结束
    public static void main(String[] args) {
        int[] arr = {1, 5, 3, 2, 8};
        test(arr);
          test(arr);
        System.out.println(Arrays.toString(arr));

    }

    public static void test(int[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0+i; j < arr.length-1; j++) {
                if(arr[j]>arr[i+1]){
                    int temp = arr[j];
                    arr[j]=arr[i+1];
                    arr[i+1] = temp;
                }
            }
        }


    }


}
